﻿using FastReport;
using FastReport.Utils;
using SMALLERP;
using SMALLERP.DataClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XJLSC.QM
{
    public partial class BHGCLDPrint : Form
    {
        DataBase db;
        DataBase db1;
        private OleDbDataReader sdr;
        private SqlDataReader sdr1;
        private Report FReport;
        private DataSet FDataSet;
        private Report FReport1;
        private DataSet FDataSet1;
        public delegate void Cdssh(object sender, EventArgs e);
        //定义委托对象
        public Cdssh cdssh;

        public BHGCLDPrint()
        {
            InitializeComponent();
        }

        private void BHGCLDPrint_Load(object sender, EventArgs e)
        {
            DataTable dt;
            int i;
            FDataSet = new DataSet();
            FReport = new Report();
            FReport.Preview = preview1;
            string thisFolder = Config.ApplicationFolder;
            DirectoryInfo theFolder = new DirectoryInfo(thisFolder + @"Reports\");
            string reportName = "";
            if (JYCX.LX == "采购进货")
            {
                reportName = theFolder + "不合格处理单.frx";
            }
            else if (JYCX.LX == "外协")
            {
                reportName = theFolder + "不合格处理单.frx";
            }
            else
            {
                reportName = theFolder + "不合格处理单.frx";
            }
            string strSql = null;
            db = new DataBase();
            try
            {
                    if (JYCX.LX == "采购进货")
                    {
                        //strSql = "select RTRIM(CAST(ROW_NUMBER()OVER(ORDER BY RTRIM(CC003)) AS CHAR(4))) AS 序号,RTRIM(CD004) 品号,RTRIM(CD005) 品名,RTRIM(CD006) 规格,RTRIM(TD024) 费用号,RTRIM(TD002) 合同号,CAST(ISNULL(TL006,0) AS real) 数量,RTRIM(MA002) 供应商,RTRIM(ISNULL(TL007,'')) 问题描述,RTRIM(ISNULL(QMSTL.UDF03,'')) 处理意见,RTRIM(ISNULL(QMSTL.CREATOR,'')) 确认人,RTRIM(ISNULL(QMSTL.UDF04,'')) 备注,TA002 单号,CC003 日期  from QMSTA LEFT JOIN PURCD ON TA001=CD001 AND TA002=CD002 AND TA003=CD003 LEFT JOIN PURCC ON CD001=CC001 AND CD002=CC002 LEFT JOIN PURTD ON CD010=TD001 AND CD011=TD002 AND CD012=TD003 LEFT JOIN PURMA ON CC005=MA001 LEFT JOIN QMSTL ON CD001=TL001 AND CD002=TL002 AND CD003=TL003 WHERE TA008>0 AND TA001='" + JYCX.DB + "' AND TA002='" + JYCX.DH + "'";
                          strSql = "select RTRIM(CAST(ROW_NUMBER()OVER(ORDER BY RTRIM(TG003)) AS CHAR(4))) AS 序号,RTRIM(TH004) 品号,RTRIM(TH005) 品名,RTRIM(TH006) 规格,RTRIM(TD024) 费用号,RTRIM(TD002) 合同号,CAST(ISNULL(TL006,0) AS real) 数量,RTRIM(MA002) 供应商,RTRIM(ISNULL(TL007,'')) 问题描述,RTRIM(ISNULL(QMSTL.UDF03,'')) 处理意见,RTRIM(ISNULL(QMSTL.CREATOR,'')) 确认人,RTRIM(ISNULL(QMSTL.UDF04,'')) 备注,TH002 单号,TG003 日期  from PURTH LEFT JOIN PURTG ON TG001=TH001 AND TG002=TH002 LEFT JOIN PURTD ON TH011=TD001 AND TH012=TD002 AND TH013=TD003 LEFT JOIN PURMA ON TG005=MA001 LEFT JOIN QMSTL ON TH001=TL001 AND TH002=TL002 AND TH003=TL003 WHERE TH017>0 AND TH001='" + JYCX.DB + "' AND TH002='" + JYCX.DH + "'";

                }
                else
                    {
                    strSql = "select RTRIM(CAST(ROW_NUMBER()OVER(ORDER BY RTRIM(TG003)) AS CHAR(4))) AS 序号,RTRIM(TH004) 品号,RTRIM(TH005) 品名,RTRIM(TH006) 规格,RTRIM(TD024) 费用号,RTRIM(TD002) 合同号,CAST(ISNULL(TL006,0) AS real) 数量,RTRIM(MA002) 供应商,RTRIM(ISNULL(TL007,'')) 问题描述,RTRIM(ISNULL(QMSTL.UDF03,'')) 处理意见,RTRIM(ISNULL(QMSTL.CREATOR,'')) 确认人,RTRIM(ISNULL(QMSTL.UDF04,'')) 备注,TH002 单号,TG003 日期  from PURTH LEFT JOIN PURTG ON TG001=TH001 AND TG002=TH002 LEFT JOIN PURTD ON TH011=TD001 AND TH012=TD002 AND TH013=TD003 LEFT JOIN PURMA ON TG005=MA001 LEFT JOIN QMSTL ON TH001=TL001 AND TH002=TL002 AND TH003=TL003 WHERE TH017>0 AND TH001='" + JYCX.DB + "' AND TH002='" + JYCX.DH + "'";

                }

                FReport = new Report();
                    FDataSet = db.GetDataSet1(strSql, "Table");
                    dt = db.GetDataSet1(strSql, "PURTD").Tables["PURTD"];
                    FReport.Load(reportName);
                    FReport.RegisterData(FDataSet);
                    FReport.Prepare();
                    FReport.ShowPrepared();
                //FReport.PrintSettings.ShowDialog = false;
                //FReport.Print();

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }           
                      
        }
    }
}
